Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
vite-plugin-node-polyfills
Advanced tools
A Vite plugin to polyfill Node's Core Modules for browser environments.
A Vite plugin to polyfill Node's Core Modules for browser environments. Supports node:
protocol imports.
Module "stream" has been externalized for browser compatibility. Cannot access "stream.Readable" in client code.
Since browsers do not support Node's Core Modules, packages that use them must be polyfilled to function in browser environments. In an attempt to prevent runtime errors, Vite produces errors or warnings when your code references builtin modules such as fs
or path
.
Install the package as a dev dependency.
# npm
npm install --save-dev vite-plugin-node-polyfills
# pnpm
pnpm install --save-dev vite-plugin-node-polyfills
# yarn
yarn add --dev vite-plugin-node-polyfills
Add the plugin to your vite.config.ts
file.
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
nodePolyfills(),
],
})
The following options are available to customize it for your needs.
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
nodePolyfills({
// To add only specific polyfills, add them here. If no option is passed, adds all polyfills
include: ['path'],
// To exclude specific polyfills, add them to this list. Note: if include is provided, this has no effect
exclude: [
'http', // Excludes the polyfill for `http` and `node:http`.
],
// Whether to polyfill specific globals.
globals: {
Buffer: true, // can also be 'build', 'dev', or false
global: true,
process: true,
},
// Override the default polyfills for specific modules.
overrides: {
// Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it.
fs: 'memfs',
},
// Whether to polyfill `node:` protocol imports.
protocolImports: true,
}),
],
})
[
'_stream_duplex',
'_stream_passthrough',
'_stream_readable',
'_stream_transform',
'_stream_writable',
'assert',
'buffer',
'child_process',
'cluster',
'console',
'constants',
'crypto',
'dgram',
'dns',
'domain',
'events',
'fs',
'http',
'http2',
'https',
'module',
'net',
'os',
'path',
'process',
'punycode',
'querystring',
'readline',
'repl',
'stream',
'string_decoder',
'sys',
'timers',
'timers/promises',
'tls',
'tty',
'url',
'util',
'vm',
'zlib',
]
Hello! My name is David, and in my spare time, I build tools to help developers be more productive. If you find my work valuable, I would really appreciate a sponsorship or donation. If you want to see more of my work, check out davidmyers.dev.
Thanks for your support! 🪴
FAQs
A Vite plugin to polyfill Node's Core Modules for browser environments.
The npm package vite-plugin-node-polyfills receives a total of 365,573 weekly downloads. As such, vite-plugin-node-polyfills popularity was classified as popular.
We found that vite-plugin-node-polyfills demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.